package com.mongo.operation.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * @author lumia 地表最强bug
 * @DATE : 2019/8/8
 * @description :
 */
public class ShiftDateUtil {
    /* //日期转换为时间戳 */
    public static String stampToTime(String stamp) {

        String sd = "";
        try {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            Date date = sdf.parse(stamp);
            long ts = date.getTime();
            sd = String.valueOf(ts);
            return sd;
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return sd;

    }

    //时间戳转换日期 *
    public static long timeToStamp(String timers) {
        Date d = new Date();
        long timeStemp = 0;
        try {
            SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
            d = sf.parse(timers);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        timeStemp = d.getTime();
        return timeStemp;
    }

    public static String getMonth() {
        Calendar c = Calendar.getInstance();
        c.add(Calendar.MONTH, -6);
        return c.get(Calendar.YEAR) + "-" + c.get(Calendar.MONTH) + "-" + c.get(Calendar.DATE);
    }
}
